package com.jianger.utils;


import com.jianger.conf.ConfigurationManager;
import com.jianger.conf.Constants;
import org.apache.commons.dbcp.BasicDataSource;

import javax.sql.DataSource;
import java.sql.Connection;

/**
 * @author jianger
 * @ date  2018/3/29-14:50
 * @project com.spark.utils
 */
public class JDBCUtils {

    private static Connection conn = null;
    private static String driver;
    private static String url;
    private static String userName;
    private static String password;

    public static BasicDataSource dataSource = new BasicDataSource();
    // 获得数据源，获得链接
    static {
        try {
            driver = ConfigurationManager.getProperty(Constants.JDBC_DRIVER);
            url = ConfigurationManager.getProperty(Constants.JDBC_URL);
            userName = ConfigurationManager.getProperty(Constants.JDBC_USER);
            password = ConfigurationManager.getProperty(Constants.JDBC_PASSWORD);
            dataSource.setDriverClassName(driver);
            dataSource.setUrl(url);
            dataSource.setUsername(userName);
            dataSource.setPassword(password);
            conn = dataSource.getConnection();
        } catch (Exception e) {

        }
    }
    // 提供获取链接的方法

    public static Connection getConn() {
        return conn;
    }
    //提供获得数据源的方法

    public static DataSource getDataSource() {
        return dataSource;

    }


}
